package com.ocm.core.exception;

public abstract class ExceptionCode {
    private int messagecode = -1;

    public abstract String getMessage(int messageCode);

    public void setMessageCode(int messageCode) {
        this.messagecode = messageCode;
    }

    public String getMessage() {
        return this.getMessage(this.messagecode);
    }
    
    @SuppressWarnings("unchecked")
    public static<T extends ExceptionCode> T instance(Class<T> classException, int messageCode){
        ExceptionCode exceptionCode;
        try {
            exceptionCode = classException.newInstance();
            exceptionCode.setMessageCode(messageCode);
            return (T) exceptionCode;
        } catch (InstantiationException e) {
            throw new OCMRuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new OCMRuntimeException(e);
        }
    }
}
